(function ($) {
    NProgress.start();
    window.onload = function () {
        NProgress.done();
    };
    $(function () {

        $.ajax({
            url: '../hive/assets/data/frame.json',
            type: "GET",//请求方式为get
            dataType: "json", //返回数据格式为json
            success: function (data) {
                var firstdaryHtml = '';
                var secondaryHtml = '';
                var secondaryHideHtml = '';
                var thirdaryHtml = '';
                var thirdaryHideHtml = '';
                $.each(data, function (index, value) {

                    $.each(value.list, function (index2, value2) {

                        $.each(value2.list, function (index3, value3) {
                            thirdaryHtml += '<li><input class="hidden" value="' + value3.page + '"/><a  target="mainFrame" class="openPage"><span class="l menu-label">' + value3.thirdDary + '</span><span class="normal icon-font">&nbsp;</span></a></li>';
                            thirdaryHideHtml += '<li><input class="hidden" value="' + value3.page + '"/><a class="_menu-link openPage" target="mainFrame"> <span data="95" class="l menu-label">' + value3.thirdDary + '</span><span class="normal icon-font"></span></a></li>';

                        });

                        thirdaryHtml = '<ul class="open expandable-level1 expandable-content">' + thirdaryHtml + '</ul>';//三级菜单
                        thirdaryHideHtml = '<ul class="item-content hm-scroll hidden"><li class="nav-title">' + value2.secondDary + '</li>' + thirdaryHideHtml + '</ul>';

                        var remainder = parseInt(index2 % 5);
                        var color = "";
                        switch (remainder) {
                            case 0:
                                color = "#009ee1";
                                break;
                            case 1:
                                color = "#3ebc7d";
                                break;
                            case 2:
                                color = "#f8aa14";
                                break;
                            case 3:
                                color = "#ff7595";
                                break;
                            case 4:
                                color = "#588afc";
                                break;
                        }


                        secondaryHtml += '<li class="flow-analysis menu-item selected clearfix" ><a href="javascript:void(0)" class="expandable recordable open"><span class="fa ' + value2.icon + ' " style="vertical-align: middle;font-size: 22px;margin-left:20px;margin-right: 8px;color: ' + color + ';"></span><span class="item-title">' + value2.secondDary + '</span></a>' + thirdaryHtml + '</li>';

                        secondaryHideHtml += '<li class="flow-analysis menu-item clearfix hover-menu"><span class="fa ' + value2.icon + ' " style="vertical-align: middle;font-size:28px;color:' + color + ';"></span000>' + thirdaryHideHtml + '</li>';
                        thirdaryHtml = '';

                        thirdaryHideHtml = '';


                    });
                    if (index != 0) {
                        firstdaryHtml += '<a data-toggle="menubar" href="#verticaltab' + index + '"' + ' role="button">' + value.firstdary + '</a>';
                        secondaryHtml = '<ul class="nav hm-scroll hidden" id="verticaltab' + index + '">' + secondaryHtml + '</ul>';
                        secondaryHideHtml = '<ul class="simple-nav hidden" id="verticaltab' + index + 'simple" >' + secondaryHideHtml + '</ul>';
                    } else {
                        firstdaryHtml += '<a class="selected"  href="#verticaltab' + index + '"' + ' role="button">' + value.firstdary + '</a>';
                        secondaryHtml = '<ul class="nav hm-scroll" id="verticaltab' + index + '">' + secondaryHtml + '</ul>';
                        secondaryHideHtml = '<ul class="simple-nav " id="verticaltab' + index + 'simple" >' + secondaryHideHtml + '</ul>';
                    }
                    $("#slid_nav").append(secondaryHtml);
                    $(".simple-nav-wrapper").append(secondaryHideHtml);
                    secondaryHtml = '';
                    secondaryHideHtml = '';
                });

                $(".view-tab").append(firstdaryHtml);
            }
        });


    });
    $().ready(function () {
        var url = GetQueryString('url');
        $("#mainFrame").attr('src', url);

        //  var $menuItem = $(".nav-wrapper .nav a");
        $(document).on('click', '.view-tab a:not(".default-a")', function () {
            var $menu = $(".nav-wrapper .nav");
            var $simplemenu = $(".simple-nav-wrapper .simple-nav");

            var $this = $(this);
            $(".view-tab a").removeClass("selected");
            $this.addClass("selected");

            //menu
            var $currentMenu = $($this.attr("href"));
            $menu.addClass('hidden');
            $currentMenu.removeClass('hidden');

            //simpleMenu
            var $currentSimpleMenu = $($this.attr("href") + "simple");
            $simplemenu.addClass('hidden');
            $currentSimpleMenu.removeClass('hidden');
            return false;
        });

        $(document).on('click', '.nav-wrapper .nav a', function () {
            var $this = $(this);
            var $menuItem = $(".nav-wrapper .nav a");
            $menuItem.removeClass("selected");
            $this.addClass("selected");
        });


        var resizeContentH = function (contentID, leftId) {
            jQuery(contentID).height(jQuery(window).height() - 50);
            jQuery("#" + leftId).height(jQuery(document).height() - 70);
        };

        /*窗口尺寸重载*/
        resizeContentH("#mainFrame", "aside");
        $(window).resize(function () {
            resizeContentH("#mainFrame", "aside");
        });


        $("#cuttle").on('click', function (event) {
            if ($("#aside").outerWidth() > 65) {
                /*       $("#cuttle").attr('src', '../global/img/cuttle.png');*/
                $("#cuttle").removeClass('icon-cuttle').addClass('icon-spread');
                $("#aside").animate({width: '64px'});
                $("#logo").animate({width: '56px', paddingLeft: '8px'});

                $(".right_nav").addClass('open').removeClass('close');

                setTimeout(function () {
                    $(".nav-wrapper").addClass('hidden');
                    $(".simple-nav-wrapper").removeClass('hidden');
                    $("#companyName").addClass('hidden');
                }, 200)
            } else {
                // $("#cuttle").attr('src', '../global/img/back.png');
                $("#cuttle").removeClass('icon-spread').addClass('icon-cuttle');

                $('#aside').animate({width: '180px'});
                $('#logo').animate({width: '160px', paddingLeft: '20px',});

                $(".right_nav").removeClass('open').addClass('close');
                setTimeout(function () {
                    $(".nav-wrapper").removeClass('hidden');
                    $(".simple-nav-wrapper").addClass('hidden');
                    $("#companyName").removeClass('hidden');
                }, 200);

            }
            event.stopPropagation();
        });


        //三级菜单闭合或者展开
        $(document).on('click', ".expandable", function () {
            $this = $(this);
            var uClass = $this.next().attr("class");
            if (uClass.indexOf("open") == 0) {
                $this.next().css('display', 'none');
                $this.next().attr("class", "close expandable-level1 expandable-content");
            } else {
                $this.next().css('display', 'block');
                $this.next().attr("class", "open expandable-level1 expandable-content");
            }
        });

        //鼠标移上去和移下来事件
        $(document).on("mouseover", '.hover-menu', function () {
            $this = $(this);
            $this.find(".item-content").attr("class", "item-content hm-scroll");
            $this.find(".item-content").parent('li').addClass("a");
        });
        $(document).on("mouseout", ".hover-menu", function () {
            $this = $(this);
            $this.find(".item-content").attr("class", "item-content hm-scroll hide");
            $this.find(".item-content").parent('li').removeClass("a");
        });

        $(function () {
            $(".top-nav ul li:has(ul)").hover(function () {
                $(this).children("ul").stop(true, true).slideDown(400);
            }, function () {
                $(this).children("ul").stop(true, true).slideUp("fast");
            });
        })
    });

    /*打开新页面*/
    $(document).on('click', '.openPage', function (e) {
        var newPage = $(this).prev().val();
        $("#mainFrame").attr('src', newPage);
        e.stopPropagation();
    });

    function _send(type, sel, val) {
        //alert(v);
        if (type == "append") {
            $("#mainFrame").contents().find('#' + sel).append(val);
        } else if (type == "val") {
            $("#mainFrame").contents().find('#' + sel).val(val);
        } else if (type == "html") {
            $("#mainFrame").contents().find('#' + sel).html(val);
        } else if (type == "method") {//调用子页面的receive方法
            $("#mainFrame")[0].contentWindow.receive(val);
        }

    }

    function _get(sel, val) {
        if (val)
            return $("#mainFrame").contents().find('#' + sel).find(val);
        else
            return $("#mainFrame").contents().find('#' + sel).val();
    }


//urlEncode
    function genUrl(url) {
        return url + "?trueUrl=" + encodeURIComponent(url);
    }
    $(function (e) {
        $("#fullScreen").on('click', function () {
            $("#content").fullScreen();
            window.event.stopPropagation();
        })
    })

    /*   //var intDiff = "0"; //倒计时总秒数量
     var intDiff = "0"; //倒计时总秒数量
     var status = "2";
     function timer(intDiff) {
     window.setInterval(function () {
     var day = 0,
     hour = 0,
     minute = 0,
     second = 0; //时间默认值
     if (intDiff > 0) {
     day = Math.floor(intDiff / (60 * 60 * 24));
     hour = Math.floor(intDiff / (60 * 60)) - (day * 24);
     minute = Math.floor(intDiff / 60) - (day * 24 * 60) - (hour * 60);
     second = Math.floor(intDiff) - (day * 24 * 60 * 60) - (hour * 60 * 60) - (minute * 60);
     } else if (intDiff == 0) {
     if (status != '' && status == '0') {
     certificationTips();
     } else if (status != '' && status == '1') {
     window.location.href = "/shop/companyinfo/incertificationForm";
     } else if (status != '' && status == '3') {
     window.location.href = "/shop/companyinfo/failverified";
     }
     }
     if (minute <= 9) minute = '0' + minute;
     if (second <= 9) second = '0' + second;
     $('#day_show').html(day + "天");
     $('#hour_show').html('<s id="h"></s>' + hour + '时');
     $('#minute_show').html('<s></s>' + minute + '分');
     $('#second_show').html('<s></s>' + second + '秒');
     intDiff--;
     }, 1000);
     }

     function updateTipsInfo() {
     var tipsInfo = "";
     if (tipsInfo == '1') {
     layer.msg('系统提示<br><br>您的企业认证已通过,欢迎使用数字营销平台!<br><br>', {
     skin: 'layui-layer-molv' //样式类名
     , closeBtn: 0
     }, function () {
     $.ajax({
     url: "/shop/companyinfo/updateTipsInfo",
     type: 'GET',
     data: {
     "tipsInfo": "0"
     },
     success: function (data) {
     if (data.isOk == true) {

     } else {

     }
     }
     });
     })
     }
     }

     $(function () {
     timer(intDiff);
     setTimeout(updateTipsInfo, 1000);


     });
     */

    /*    //提示认证弹窗
     function certificationTips() {
     layer.open({
     closeBtn: 0, //不显示关闭按钮
     title: false, //不显示标题
     type: 1,
     skin: 'layui-layer-rim', //加上边框
     area: ['380px', '240px'], //宽高
     content: '<h2 style="text-align: center;margin-top:30px;font-size: 24px;color: #303e45">系统信息</h2><br><br>' +
     '<h2 style="text-align: center;font-size: 14px;color: #5a6069">您的试用期已到期,感谢您的使用!</h2>' +
     '<h3 style="text-align: center;color: #a3afb7">如果想继续使用您可以通过<u class="certification" style="color: #15baff" onclick="certification()">企业认证</u>成为正式用户!</h3><br><br>' +
     '<div style="text-align: center"><button type="button" class="btn btn-primary"  style="height: 28px;border-radius: 5px;background-color: #f8f8f8;border:solid 1px #e5e5e5" onclick="logout()">安全退出</button><button type="button" class="btn btn-success" style="background-color: #15baff;height: 28px;border-radius: 5px;margin-left:8px;color:white" onclick="certification()">立即认证</button></div>'
     });
     }*/
//点击退出
    function logout() {
        window.location = "/member/logout";
    }

//点击认证
    function certification() {
        window.location.href = "/shop/companyinfo/certificationForm"
    }
    function GetQueryString(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if (r != null) return unescape(r[2]);
        return null;
    }
})(jQuery);